package com.fanrui.code.player;

import org.apache.commons.lang3.RandomUtils;

import com.fanrui.code.dao.EParameterType;
import com.fanrui.code.dao.ParameterConfigManager;
import com.fanrui.code.util.core.JsonUtil;
import com.fanrui.proto.cmd.CurrencyType;
import com.google.gson.annotations.Expose;

public class ChessPlayerInfo {
	@Expose
	private String nickName = "";
	@Expose
	private String headUrl = "";
	private String ip = "";
	@Expose
	private String location = "";
	@Expose
	private String latitudeAndLongitude = "";
	@Expose
	private boolean sex = false;
	@Expose
	private String freestyle = "";
	@Expose
	private long gold = 0;
	@Expose
	private long score = 0;

	public ChessPlayerInfo(long playerId) {
		this(PlayerManager.getInstance().findOrCreatePlayer(playerId));
	}

	public ChessPlayerInfo(Player player) {
		if (player != null) {
			this.nickName = player.getNickname();
			this.headUrl = player.getHeadUrl();
			this.gold = player.getCurrencyValue(CurrencyType.C_Gold);
			this.score = player.getCurrencyValue(CurrencyType.C_Money);
			if(player.getSex() != null) {
				this.sex = player.getSex().equals("男") ? true : false;
			}
		} else {
			setDefault();
		}
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getHeadUrl() {
		return headUrl;
	}

	public void setHeadUrl(String headUrl) {
		this.headUrl = headUrl;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getLocation() {
		return location == null ? "" : location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getLatitudeAndLongitude() {
		return latitudeAndLongitude == null ? "" : latitudeAndLongitude;
	}

	public void setLatitudeAndLongitude(String latitudeAndLongitude) {
		this.latitudeAndLongitude = latitudeAndLongitude;
	}

	public boolean isSex() {
		return sex;
	}

	public void setSex(boolean sex) {
		this.sex = sex;
	}

	public String getFreestyle() {
		return freestyle == null ? "" : freestyle;
	}

	public void setFreestyle(String freestyle) {
		this.freestyle = freestyle;
	}

	public long getGold() {
		return gold;
	}

	public void setGold(long gold) {
		this.gold = gold;
	}

	public long getScore() {
		return score;
	}

	public void setScore(long score) {
		this.score = score;
	}

	public void setDefault() {
		setGold(10000);
		setHeadUrl(JsonUtil.getRandomElementByJsonArray(ParameterConfigManager.getInstance().getStrListParameter(EParameterType.VisitorHeadUrl)));
		//setHeadUrl(JsonUtil.getRandomElementByJsonArray(ParameterConfigManager.getInstance().getStrParameter(EParameterType.VisitorHeadUrl)).replace("\"", ""));
		setNickName(JsonUtil.getRandomElementByJsonArray(ParameterConfigManager.getInstance().getStrListParameter(EParameterType.VisitorName)));
		setFreestyle("");
		setLatitudeAndLongitude("45度");
		setLocation("重庆");
//		setIp("0.0.0.0");
		setScore(0);
		setSex(RandomUtils.nextBoolean());
	}
}